<%@ page contentType="text/html; charset=utf-8" language="java"
	import="java.sql.*" errorPage=""%>
<%@page import="org.acegisecurity.Authentication"%>
<%@page import="org.acegisecurity.context.SecurityContextHolder"%>
<%@page import="org.acegisecurity.userdetails.UserDetails"%>
<%@taglib uri="http://acegisecurity.org/authz" prefix="authz"%><%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="java.util.Date" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>

		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Home page</title>


	</head>
	<!-- toan trang welcome -->
	<body topmargin="0">
		<f:view>
		<center>
			<table width="780" height="1000" border="1" cellpadding="0"
				cellspacing="0">
				<tr>
					<td height="154">
						<table width="780" height="124" border="0" cellpadding="0"
							cellspacing="0">
							<tr>
								<td height="130"><%@ include file="header.jsp"%>
								</td>
							</tr>


							<tr>
								<!-- link bar -->

								<td height="24" background="icon/link.gif">
									<%=new Date()%>					 
				Welcome 
				<authz:authorize ifAnyGranted="ROLE_CUSTOMER,ROLE_ADMIN">
					<authz:authentication operation="username"></authz:authentication>
				
				
					<a href="j_acegi_logout">Logout</a>
				
					</authz:authorize>
				
				<authz:authorize ifAllGranted="ROLE_ANONYMOUS"> guest 
				<a href="login.faces">Login</a>
				</authz:authorize>
				 
								</td>
							</tr>
						</table>

					</td>

				</tr>
				<!-- table menu,trang chu, hot banner -->
				<tr>
					<td>
						<table width="780" height="846" border="1" cellpadding="0"
							cellspacing="0">
							<tr valign="top">
								<td width="170" bgcolor="#5EB1F0" align="left">
									

									<%@ include file="/menu.jsp"%></td>

								<td width="472" bgcolor="#FFFFFF" align="center">
			<h:form>
				<table cellpadding="0" cellspacing="0">
				<Tr>
				<td>
				Product list , news , and hot banner <br/>
				<br/>
				</td>
				</Tr>
				
				<Tr>
				<td>
				<%
					Integer chiaNho = 0;
				// phan trang 
				Integer sizePage;
				int	iPage=0;
					
				String currentPage = request.getParameter("IPAGE");
				
				if(currentPage!=null) 
							{
							iPage = Integer.parseInt(currentPage);
							// xu ly viec hien thi thoi,
							//trang 0 la trang 1
							iPage=iPage-1;
							}
				
				int startPos =(iPage)*12;
				int endPos =(iPage+1)*12;
				%>
				
				
				<table border="1" width="100%" cellpadding="0" cellspacing="0">
					<!--  khung lam viec chinh -->
				<tr>
				
			<!--<c:set var="size" scope="page" value="#{matHang.listSize}"></c:set>-->
				<!-- begin va end trong c:foreach hoat dong ko tot
					gia su begin=0 end=3 cung tuong duong voi begin=3 end=6
					nen cach lam khac la phai if
				 -->				
				 	
										
					<c:forEach items="#{matHang.matHangs}" var="mathang"    >
									
					<%
					chiaNho = chiaNho + 1;
					
					if((chiaNho>startPos) &&(chiaNho<=endPos))
							{
					
					%>
					  
				  
					
						<td width="155" >
							
								<table cellpadding="2" cellspacing="2" border="0" align="center">
									<tr>
										<td width="155" height="155">

											<!--  commandButton ko ho tro anh gif -->
										
									<h:commandButton action="#{matHang.details}" image="picture/sanphamNho/#{mathang.maHang}.jpg" 
												
												style="width: 150px;"  > <br/>
												
													<f:setPropertyActionListener
													
												target="#{requestScope.mathang}" value="#{mathang}" />
									
										
									</h:commandButton>
									
																
									
									</td>
									
										</tr>
										
										<tr valign="bottom">
										<td>
											<c:set var="gifStateMatHang" value="#{mathang.tinhTrang}" scope="page"/> 
											<center> <img src="icon/${gifStateMatHang}.gif"/> </center>
												<c:remove var="gifStateMatHang"/>  
										<br/>
											
									
											
											
											Product ID: <h:outputText value="#{mathang.maHang}"></h:outputText> <br/>
									Price :<h:outputText value="#{mathang.donGia}"></h:outputText> $<br/>
										
										
											
											
									<!-- trong method addtocart nho phai put matHang() cho selected -->
									
								<h:commandLink value="Add to cart" action="#{matHang.addToCart}">
										<f:setPropertyActionListener target="#{requestScope.mathang}" value="#{mathang}" />
									</h:commandLink>
									<br/>
								<h:commandLink value="Buy" action="#{matHang.buy}">
								<f:setPropertyActionListener target="#{requestScope.mathang}" value="#{mathang}" />
								</h:commandLink>
										</td>
										
										</tr>
								</table>
								
								</td>
								
							<%} %>				
									
						
						<%//dung de chia nho bang san pham
					if ((chiaNho % 3) == 0) {
							%>
										<tr>
										</tr>
						<%
						}
						;
						%>
					
				</c:forEach>
				
					
			</tr>
			
					
				
				</table>
				<!-- chon hien thi 12 mat hang trong 1 trang
				co so luong mat hang ta se tinh duoc so trang can
				hien thi la sizePage=size/11
				 -->
				
				Total product : <%=chiaNho %> 
				
				<%
				sizePage = chiaNho / 12 +1;
				if( (chiaNho % 12)==0) sizePage=sizePage-1;
				// chung ta se kiem tra so luong trang co lon hon
				//1 hay ko sau
				if (sizePage>1)
		{		
		%>
				| Page(<%=iPage+1%>/<%=sizePage%>) :
					
					<%
					Integer i;
					for (i = 1; i <= sizePage; i++) 
					{
					%>
					<a href="TrangChu.faces?IPAGE=<%=i%>"><%=i%></a>
				
					
					<%};%>
		<%}; %>
					<br/>
					
					
				</td>
				</Tr>
				
				</table>
				
				
				
			</h:form>									
									
									
								</td>
								<td width="130" bgcolor="#FFFFFF">


									hot banner
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>

			<font color="red">ANH HONG PRODUCTION AND IMPORT-EXPORT
				CO.,LTD<br/> Add. Kim Son District , Ninh Binh Province , Viet
				Nam <br/> Tel:84.30.862059-Fax:84.30.862384
				Email:Anhhongltd@pmail.vnn.vn<br/> Copyright : HCMUTE 2008 </font>

		</center>		
		



		</f:view>






	</body>

</html>